<html>
<head><meta charset="utf-8"><title>resource efficiency · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html">resource efficiency</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232969092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/232969092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> protty <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#232969092">(Apr 03 2021 at 01:02)</a>:</h4>
<p>Reading through the characters, there feels like one is missing from the description. Was wondering if this was considered and, if so, why was it rejected.</p>
<p>This character would be someone whos primary goal is resource scalability and efficiency. Its similar to the top priority of Alan but has a different agenda than performance in mind. They would also have similar background to Grace, having experience in systems programming, but focused more on what they can get out of the machine as opposed to how they can do so using the least amount of unsafety. The choice of Rust for them would be focused on the non-safety features such as RAII, efficient code generation, type constraints, and other properties that help build scalable and reliant systems.</p>
<p>The current rust ecosystem as well as the APIs set by the core library for Futures feel as though they exclude this sort of character from the syntactical benefits of async/await. Has this sort of character been considered?</p>



<a name="233288626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233288626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233288626">(Apr 06 2021 at 09:11)</a>:</h4>
<p><span class="user-mention" data-user-id="250722">@protty</span> I feel that goal is kind of implict in Grace. It's her "expectation". It's not her <em>goal</em> in using Rust: she can get it from C++, but it's something Rust had better provide.</p>



<a name="233288648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233288648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233288648">(Apr 06 2021 at 09:11)</a>:</h4>
<p>It's also Alan's explicit <em>goal</em></p>



<a name="233288694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233288694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233288694">(Apr 06 2021 at 09:12)</a>:</h4>
<p>(high performance)</p>



<a name="233464263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233464263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> protty <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233464263">(Apr 07 2021 at 10:27)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I think there might be a miscommunication:</p>
<p>Grace's primary goal is memory safety which frequently butts heads against resource efficiency, particularly memory efficiency. Some examples of this are the awkward use of addr_of() with intrusive memory and the unsoundness of some self-referential data structures.</p>
<p>Grace's expectation about "getting the same perf as C or C++" and Alan's goal of "performance" are both about performance not resource efficiency. I tried to hint at this difference by saying Alan had a similar but different agenda. Resource efficiency is more for reasoning about the costs of things in order to scale them (think memory use and latency). Performance is more about doing whatever will get the best local metrics (think execution time and throughput). </p>
<p>Perf and Efficiency can contradict each other and the latter is not really mentioned in any of the characters. In the case of Rust async, things like 1) having to dynamically allocate the Future if created generically for safety due to the unbounded lifetime of the Waker or 2) being unable to store the Waker in an atomic don't necessarily change the performance for a lot of common application code. It does however limit what you can do outside of the common case and forces you to introduce costs that aren't present in other programming environments, which affects resource efficiency.</p>



<a name="233511758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233511758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233511758">(Apr 07 2021 at 15:34)</a>:</h4>
<p><span class="user-mention" data-user-id="250722">@protty</span> Grace's primary goal <em>in using Rust</em> (instead of C++) is getting safety. It's not her only goal <em>overall</em></p>



<a name="233511866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233511866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233511866">(Apr 07 2021 at 15:35)</a>:</h4>
<p>I do agree that I am using performance loosely to mean "efficiency of whatever kind matters to them in the moment", and it's probably worth separating out resource efficiency from performance from (e.g.) power consumption</p>



<a name="233511966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233511966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233511966">(Apr 07 2021 at 15:35)</a>:</h4>
<p>It also sounds like I could probably take a stab at reworking the character descriptions to make things clearer</p>



<a name="233512041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233512041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233512041">(Apr 07 2021 at 15:36)</a>:</h4>
<p>Regardless, though, of whether we add another character, I'd love to hear your thoughts on what stories this would influence and how!</p>



<a name="233512120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233512120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233512120">(Apr 07 2021 at 15:36)</a>:</h4>
<p>Like, what are some of the places where <em>resource efficiency</em> is challenging (or well suppported!) in async Rust today?</p>



<a name="233512188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233512188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233512188">(Apr 07 2021 at 15:36)</a>:</h4>
<p>Also, I broke this out into its own topic for ease of future reference :)</p>



<a name="233512262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233512262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233512262">(Apr 07 2021 at 15:37)</a>:</h4>
<p>Maybe the other point is that we should include a <strong>project</strong> where resource efficiency is a key consideration</p>



<a name="233512275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233512275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233512275">(Apr 07 2021 at 15:37)</a>:</h4>
<p>so that shiny future stories have to discuss their impact on that</p>



<a name="233517278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233517278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andrew Chin (eminence) <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233517278">(Apr 07 2021 at 16:06)</a>:</h4>
<p>We have a <a href="https://rust-lang.github.io/wg-async-foundations/vision/status_quo/barbara_carefully_dismisses_embedded_future.html">story</a> about Barbara looking at futures for embedded programming on machines with only kilobytes of memory.  i guess this is a type of "resource efficiency", but is likely a different type of efficiency than what <span class="user-mention" data-user-id="250722">@protty</span> has in mind</p>



<a name="233517505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233517505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andrew Chin (eminence) <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233517505">(Apr 07 2021 at 16:08)</a>:</h4>
<p>for me personally, the stories are more important than the character.   the character provides a rough framework to deciding how much they know, and the kinds of things that they struggle with.  but the story is what really explains the experience</p>



<a name="233590484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233590484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> protty <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233590484">(Apr 08 2021 at 01:56)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> That clarification on Grace's motives helps. I was under the incorrect impression that the top priority for each character eclipses everything else to the point of possibly sacrificing other attributes to achieve it. Taking the "expectation" into context explains why that's not the case.</p>
<p>Im not sure what stories could be changes as I haven't really read many of them (probably should). The one mentioned by <span class="user-mention" data-user-id="222286">@Andrew Chin (eminence)</span> is a good representation of resource efficiency; particularly about writing libraries which are pluggable to many environments (e.g. the use of intrusive memory) and working in resource constrained environments. The desire for these properties from libraries seems to have a <a href="https://ferrous-systems.com/blog/embedded-async-await/#prior-art">decent</a> <a href="https://tomaka.medium.com/a-look-back-at-asynchronous-rust-d54d63934a1c#68df">demand</a> in the wild.</p>
<p>It should be noted that embedded wouldn't be the only sphere here. It could also include things like writing network services which are meant to scale (closer to what the hardware allows) on low resource cloud vms or non-embedded IoT devices. In fact that itself could be taken as an example project in which resource efficiency is the goal. </p>
<p>Rust async has a few good example of resource efficiency:</p>
<ul>
<li>The state machine generated by async/await syntax appears to currently be a good tradeoff in the Future's memory consumption compared to the syntactic sugar offered by async/await.</li>
<li>The ability for Future polls() to be inlined is also a good design decision in optimizing code gen.</li>
<li>Passing a Context for each poll() allows resume-based-state which would otherwise require globals/threadlocals/etc (as it was originally in MVP).</li>
</ul>
<p>Rust async is challenging in resource efficiency for most other parts I can think of:</p>
<ul>
<li>Requiring Drop to cancel + lack of async Drop ends up in completion apis having to make the data its working with dynamically tracked to appease memory safety.</li>
<li>Waker being Sync requiring synchronization for wake()/wake_by_ref().</li>
<li>Waker having to be updated on re-poll() introduces unnecessary synchronization.</li>
<li>Waker being 2 ptrs large makes said synchronization either racy (AtomicWaker) or blocking (Mutex).</li>
<li>Waker being opaque means its unspecified to unpack vtable &amp; ptr. Doing so is useful for container_of() logic on the Waker's content or the Context's reference.</li>
<li>Waker being Cloneable means the Future it's waking up either needs to be static, not wake-able ("overriding" as explained in andrew's linked story), or have dynamic lifetime (implying dynamic alloc / heap) to be used safely generically when it may not need these overheads.</li>
</ul>



<a name="233595204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/resource%20efficiency/near/233595204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andrew Chin (eminence) <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/resource.20efficiency.html#233595204">(Apr 08 2021 at 03:08)</a>:</h4>
<p>i think there is definitely room for a story here.   part of what your describing is, i think, the general expectation from rust users that rust will be efficient and not wasteful (and this expectation naturally extends to major crates in the ecosystem).  </p>
<p>but you're also getting at some good specifics about Waker that would be good document in a story.  for example, did someone implement some async code and found that it failed to live up to their expectations (perhaps Grace is porting her epoll-based C++ project to async rust), and then tries to figure out why.  Or maybe someone is trying to write their own bespoke executor (targeting some specific high-performance workload), and has to dig into a lot of the Waker specifics you mention</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>